-
Notifications
You must be signed in to change notification settings - Fork 44
[VertexAI] Refactor the LiveSession responses #1231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @a-maurice, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request refactors the handling of LiveSession responses in the VertexAI API. The primary change involves renaming the top-level struct from LiveContentResponse
to LiveSessionResponse
and reorganizing its fields into new structs that implement a shared interface, ILiveSessionMessage
. This interface is implemented by LiveSessionContent
, LiveSessionToolCall
, and LiveSessionToolCallCancellation
, each representing different types of messages from the live session. Additionally, the PR introduces helper methods for parsing lists of strings from JSON dictionaries.
Highlights
- Response Refactor: The top-level struct
LiveContentResponse
is renamed toLiveSessionResponse
, and its fields are moved into new structs (LiveSessionContent
,LiveSessionToolCall
,LiveSessionToolCallCancellation
) that implement theILiveSessionMessage
interface. - New String List Parsing Methods: The
InternalHelpers.cs
file is updated to include helper methods (TryParseStringList
andParseStringList
) for parsing lists of strings from JSON dictionaries. - ReceiveAsync Update: The
ReceiveAsync
method inLiveSession.cs
is updated to return anIAsyncEnumerable<LiveSessionResponse>
instead ofIAsyncEnumerable<LiveContentResponse>
, and the logic for determining turn completion is updated to check theTurnComplete
property of theLiveSessionContent
message.
Changelog
Click here to see the changelog
- vertexai/src/Internal/InternalHelpers.cs
- Added
TryParseStringList
method to safely attempt converting a list of objects to a list of strings. - Added
ParseStringList
method to cast a list to a string list, throwing an exception if the cast fails.
- Added
- vertexai/src/LiveContentResponse.cs
- This entire file was removed as part of the refactoring.
- vertexai/src/LiveSession.cs
- Updated the
ReceiveAsync
method to returnIAsyncEnumerable<LiveSessionResponse>
instead ofIAsyncEnumerable<LiveContentResponse>
. - Modified the
ReceiveAsync
method to checkresponse?.Message is LiveSessionContent serverContent && serverContent.TurnComplete
for turn completion.
- Updated the
- vertexai/src/LiveSessionResponse.cs
- Created a new
LiveSessionResponse
struct to encapsulate different types of messages from the live session. - Introduced the
ILiveSessionMessage
interface and implementing structs:LiveSessionContent
,LiveSessionToolCall
, andLiveSessionToolCallCancellation
. - Added logic to parse different message types from JSON responses.
- Added properties to extract text and audio content from
LiveSessionContent
.
- Created a new
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
A struct's refactor,
Fields move, no longer factor,
Interface aligns.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request refactors the LiveSession responses, renaming the top-level struct and moving fields into other structs with a shared interface. The changes seem well-structured and improve the organization of the response handling. However, there are a few areas that could be improved for clarity and completeness.
Summary of Findings
- Missing
FunctionIdsToCancel
implementation: The originalLiveContentResponse
struct had aTODO
comment forFunctionIdsToCancel
. This functionality seems to be missing in the refactoredLiveSessionToolCallCancellation
struct. It's important to ensure this feature is implemented or explicitly removed if it's no longer needed. - Incomplete
serverContent
parsing: TheLiveSessionResponse.FromJson
method has aTODO
comment indicating that other fields withinserverContent
need to be parsed. This should be addressed to ensure all relevant data is being processed. - Potential
NullReferenceException
inAudio
property: TheAudio
property inLiveSessionResponse
returnsnull
ifMessage
is not aLiveSessionContent
. This could lead to aNullReferenceException
if the caller attempts to access theAudio
property without checking ifMessage
is of the correct type.
Merge Readiness
The refactoring improves the structure of the LiveSession responses. However, the missing FunctionIdsToCancel
implementation, incomplete serverContent
parsing, and potential NullReferenceException
in the Audio
property should be addressed before merging. I am unable to approve this pull request, and recommend that it not be merged until these issues are resolved. Please have others review and approve this code before merging.
.Where(part => part.MimeType == "audio/pcm") | ||
.Select(part => part.Data.ToArray()); | ||
} | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// We don't want to pass this along to the user, so return null instead. | ||
return null; | ||
} else if (jsonDict.TryParseValue("serverContent", out Dictionary<string, object> serverContent)) { | ||
// TODO: Other fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else if (jsonDict.TryParseValue("toolCallCancellation", out Dictionary<string, object> toolCallCancellation)) { | ||
return new LiveSessionResponse(LiveSessionToolCallCancellation.FromJson(toolCallCancellation)); | ||
} else { | ||
// TODO: Determine if we want to log this, or just ignore it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
Refactor how the LiveSession responses are handled. Rename the top level struct from LiveContentResponse to LiveSessionResponse, move the various fields into other structs that use a shared interface that LiveContentResponse now contains instead.
Testing
Running locally.
Type of Change
Place an
x
the applicable box: